package library.operation;

import library.Book;
import library.ListBook;

import java.util.Scanner;

//归还书籍操作类
public class ReturnOperation implements IOperation{
    @Override
    public void work(ListBook listBook) {
        System.out.print("请输入你要归还图书的序号：");
        Scanner scanner = new Scanner(System.in);
        int index = scanner.nextInt();
        //注意输入的索引是否合法
        if(index < 0 && index >= listBook.getSize()){
            System.out.println("输入的序号非法！");
            return;
        }
        //注意是否借出，未借出，则不能归还
        Book book = listBook.getBook(index);
        if(!book.isBorrow()){
            System.out.println("这本书未借出，不用归还");
            return;
        }
        //归还书，isBorrow设置为true即可
        book.setBorrow(false);
        System.out.println("归还成功！");
    }
}
